<template>
  <header class="header" ref="headerRef">
    <div class="header-container">
      <!-- Logo区域 -->
      <div class="logo-section">
        <NuxtLink to="/" class="logo-link">
          <img :src="siteInfo.siteLogoUrl" class="logo-img" alt="Logo" />
        </NuxtLink>
      </div>

      <!-- 导航菜单区域 - 仅PC端显示 -->
      <nav class="nav-section hidden lg:flex">
        <div class="nav-menu">
          <div class="nav-item" :class="{ active: currentIdx === 0 }">
            <NuxtLink to="/" class="nav-link" @click="handlePcMenuClick({ link: '/', clickable: 1 }, 0)"> 首页 </NuxtLink>
          </div>
          <template v-for="(menu, index) in menus" :key="menu._id">
            <div
              class="nav-item"
              :class="{
                active: currentIdx === index + 1,
                disabled: menu.clickable === 0,
                'has-dropdown': menu.children && menu.children.length > 0
              }"
              @mouseenter="handleMenuHover(menu, index + 1)"
              @mouseleave="handleMenuLeave"
            >
              <NuxtLink v-if="menu.clickable === 1" :to="menu.link" class="nav-link" @click="handlePcMenuClick(menu, index + 1)">
                {{ menu.name }}
                <Icon v-if="menu.children && menu.children.length > 0" name="uil:angle-down" class="dropdown-icon" />
              </NuxtLink>
              <span v-else class="nav-link disabled-link">
                {{ menu.name }}
                <Icon v-if="menu.children && menu.children.length > 0" name="uil:angle-down" class="dropdown-icon" />
              </span>
            </div>
          </template>
        </div>
      </nav>

      <!-- 搜索区域 -->
      <div class="search-section hidden lg:block">
        <div class="search-container">
          <input type="text" v-model="searchKeyword" placeholder="搜索产品、服务..." class="search-input" @keyup="handleSearchKeyup" />
          <button class="search-btn" @click="handleSearch">
            <Icon name="uil:search" class="primary-color" />
          </button>
        </div>
      </div>

      <!-- 移动端菜单按钮 -->
      <div class="mobile-menu-btn block lg:hidden xl:hidden" @click="dialog = true">
        <Icon name="uil:bars" />
      </div>
    </div>

    <!-- 全屏下拉菜单 - 仅PC端显示 -->
    <div class="mega-dropdown hidden lg:block" :class="{ active: hoveredMenu }" @mouseenter="keepDropdownOpen" @mouseleave="handleDropdownLeave">
      <div class="mega-dropdown-content" v-if="hoveredMenu">
        <div class="dropdown-left">
          <img :src="hoveredMenu.icon || '/default-menu-icon.png'" :alt="hoveredMenu.name" class="dropdown-image" />
        </div>
        <div class="dropdown-center">
          <h3 class="dropdown-title">{{ hoveredMenu.name }}</h3>
          <p class="dropdown-description">{{ hoveredMenu.description || "暂无描述" }}</p>
          <NuxtLink :to="hoveredMenu.link" class="learn-more-btn" @click="hoveredMenu = null"> 了解更多 </NuxtLink>
        </div>
        <div class="dropdown-right">
          <div class="children-list" v-if="hoveredMenu.children && hoveredMenu.children.length > 0">
            <h4 class="children-title">相关服务</h4>
            <div class="children-grid">
              <div
                v-for="child in hoveredMenu.children"
                :key="child._id"
                class="child-item"
                :class="{ disabled: child.clickable === 0 }"
                @click="handlePcSubMenuClick(child, menus.findIndex((m) => m._id === hoveredMenu._id) + 1)"
              >
                <NuxtLink v-if="child.clickable === 1" :to="child.link" class="child-link">
                  {{ child.name }}
                </NuxtLink>
                <span v-else class="child-link disabled">
                  {{ child.name }}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 移动端右侧滑动菜单 -->
    <div class="mobile-menu-wrapper block lg:hidden">
      <div class="mobile-menu-overlay" :class="{ active: dialog }" @click="dialog = false"></div>
      <div class="mobile-menu" :class="{ active: dialog }">
        <div class="mobile-menu-header">
          <span class="menu-title">导航</span>
          <button class="close-btn" @click="dialog = false">
            <Icon name="uil:times" />
          </button>
        </div>
        <div class="mobile-menu-content">
          <!-- <div class="search-item" @click="handleMenuClick('/search')">
              <Icon name="uil:search" class="mr-2" />
              <span>搜索</span>
            </div> -->
          <div class="menu-divider"></div>
          <!-- 首页菜单项 -->
          <div class="menu-item" :class="{ active: currentIdx === 0 }">
            <div class="menu-item-content d-flex flex-justify-between" @click="handleMobileMenuClick({ link: '/', clickable: 1 }, 0)">
              <Icon name="uil:home" class="mr-2 sectionIcon" />
              <span>首页</span>
            </div>
          </div>
          <div class="menu-divider"></div>
          <template v-for="(menu, index) in menus" :key="menu._id">
            <div class="menu-item" :class="{ disabled: menu.clickable === 0, active: currentIdx === index + 1 }">
              <div class="menu-item-content d-flex flex-justify-between" @click="handleMobileMenuClick(menu, index + 1)">
                <Icon name="uil:apps" class="mr-2 sectionIcon" />
                <span>{{ menu.name }}</span>
                <Icon name="uil:angle-right" v-if="menu.children && menu.children.length > 0" />
              </div>
              <div class="submenu" v-if="menu.children && menu.children.length > 0">
                <template v-for="child in menu.children" :key="child._id">
                  <div class="submenu-item" :class="{ disabled: child.clickable === 0 }" @click="handleMobileSubMenuClick(child, index + 1)">
                    <span>{{ child.name }}</span>
                  </div>
                </template>
              </div>
            </div>
            <div class="menu-divider"></div>
          </template>
        </div>
      </div>
    </div>
  </header>
  <main class="app_main">
    <slot></slot>
  </main>
  <!-- 页尾 -->
  <footer class="footer_wrapper w-100 flex-column">
    <div class="footer_content_wrap mx-auto flex flex-justify-between">
      <!-- 菜单区：桌面端显示，子项竖排，大项横排 -->
      <div class="menu_sections hidden lg:grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 flex-1">
        <div v-for="menu in menus" :key="menu._id || menu.id" class="footer_section">
          <div class="item_title mb-2 d-flex align-center">
            <!-- <Icon name="uil:apps" class="mr-2 sectionIcon" /> -->
            <span>{{ menu.name }}</span>
          </div>
          <div v-if="menu.children && menu.children.length" class="children_list d-flex flex-column">
            <div v-for="(child, idx) in menu.children" :key="child._id || child.id" class="child_item py-2" :class="{ has_divider: idx < menu.children.length - 1 }">
              <NuxtLink
                v-if="child.clickable !== 0"
                :to="child.link"
                :target="child.isOutLink === 1 ? '_blank' : '_self'"
                class="d-flex align-center on_hover nav_link"
                @click.prevent="handlePcSubMenuClick(child)"
              >
                <span>{{ child.name }}</span>
              </NuxtLink>
              <span v-else class="d-flex align-center">
                <span>{{ child.name }}</span>
              </span>
            </div>
          </div>
          <div v-else class="children_list">
            <NuxtLink
              v-if="menu.clickable !== 0"
              :to="menu.link"
              :target="menu.isOutLink === 1 ? '_blank' : '_self'"
              class="d-flex align-center on_hover nav_link py-2"
              @click.prevent="handlePcMenuClick(menu, 0)"
            >
              <span>{{ menu.name }}</span>
            </NuxtLink>
            <span v-else class="d-flex align-center py-2">
              <span>{{ menu.name }}</span>
            </span>
          </div>
        </div>
      </div>

      <!-- 公司信息：移动端与桌面端都显示，桌面放在最右侧 -->
      <div class="company_info_section footer_content_item text-center text-md-left text-lg-left text-xl-left d-flex flex-column md:ml-8">
        <div class="item_title mb-2 d-flex align-center">
          <div class="logo">
            <img :src="siteInfo.siteLogoUrl" alt="公司logo" />
          </div>
          <div class="title">
            <NuxtLink to="/"></NuxtLink>
          </div>
        </div>
        <div class="sub_item py-2">
          <div class="item_sub_title">
            <Icon name="uil:phone" class="mr-2 sectionIcon" />
            <span>咨询电话：</span>
            <NuxtLink :to="'tel:' + companyInfo.telephone">
              <span>{{ companyInfo.telephone }}</span>
            </NuxtLink>
          </div>
        </div>
        <div class="sub_item py-2">
          <div class="item_sub_title">
            <Icon name="uil:at" class="mr-2 sectionIcon" />
            <span>邮箱：</span>
            <span>{{ companyInfo.email }}</span>
          </div>
        </div>
        <div class="sub_item py-2">
          <div class="item_sub_title">
            <Icon name="uil:map-marker" class="mr-2 sectionIcon" />
            <span>地址：</span>
            <span>{{ companyInfo.companyAddress }}</span>
          </div>
        </div>
        <div class="sub_item lg:flex-justify-start flex flex-justify-center">
          <div class="wxcode">
            <img :src="companyInfo.wechatQrCodeUrl" alt="微信二维码" class="mb-1" />
            <span>销售顾问</span>
          </div>
        </div>
      </div>
    </div>
    <div class="record_information pt-1">
      <div class="copy_right text-center">{{ siteInfo.footerInfo }}</div>
      <div class="record ml-2 mt-sm-2 mt-md-0 mt-lg-0 mt-xl-0">
        <NuxtLink to="https://beian.mps.gov.cn/#/query/webSearch" target="_blank">
          <img src="https://www.zhulikeyan.com/statics/6bb77047-ef06-437f-b55d-8d81cb32ba9b.png" class="mr-1" />
        </NuxtLink>
        <NuxtLink to="https://beian.miit.gov.cn/#/Integrated/index" target="_blank"> {{ siteInfo.siteRecord }} </NuxtLink>
      </div>
      <div class="sitemap ml-2 text-center copy_right">
        <NuxtLink to="https://www.zhulikeyan.com/sitemap.html" target="_blank"> SITEMAP </NuxtLink>
      </div>
    </div>
  </footer>
</template>

<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
const dialog = ref(false);
const hoveredMenu = ref<any>(null);
const formRef = ref<any>(null);
const currentIdx = ref<string | number>(0);
const router = useRouter();
const route = useRoute();
const appConfig = useAppConfig();
const systemConfig = appConfig.systemConfig || {};
const siteInfo = systemConfig.siteInfo || {};
const companyInfo = systemConfig.companyInfo || {};
const menus = systemConfig.menus || [];
console.log(menus, "menus");

/**
 * @breif: 页面挂载时，改变nav的高亮显示
 * @return {*}
 */
onMounted(() => {
  console.log("default 已加载完毕");
  updateActiveMenu();
});

/**
 * 根据当前路由更新菜单高亮状态
 */
const updateActiveMenu = () => {
  const currentPath = route.path;

  // 首页高亮
  if (currentPath === "/") {
    currentIdx.value = 0;
    return;
  }

  // 查找匹配的菜单项
  const matchedMenuIndex = menus.findIndex((menu: any) => {
    if (menu.link === currentPath) {
      return true;
    }
    // 检查子菜单
    if (menu.children && menu.children.length > 0) {
      return menu.children.some((child: any) => child.link === currentPath);
    }
    return false;
  });

  if (matchedMenuIndex !== -1) {
    currentIdx.value = matchedMenuIndex + 1;
  } else {
    currentIdx.value = 0; // 默认高亮首页
  }
};

// 监听路由变化，更新高亮状态
watch(
  () => route.path,
  () => {
    updateActiveMenu();
  }
);

const validate = async () => {
  const { valid } = await formRef.value.validate();
  return valid;
};

const reset = async () => {
  formRef.value.reset();
};

// 点击nav导航
const handleClickNav = (idx: number, link: string) => {
  currentIdx.value = idx;
  router.push(link);
};

/**
 * @breif: 点击产品导航的某一项
 * @param {*} idx
 * @param {*} link
 * @param {*} params
 * @return {*}
 */
const handleItemClick = (idx: number, link: string, params: string) => {
  currentIdx.value = idx;
  router.push(link);
};

/**
 * 处理菜单项点击事件
 * @param {Object} menu - 菜单项数据对象
 */
const handleMenuItemClick = (menu: any) => {
  if (menu.clickable === 0) {
    return;
  }

  if (menu.isOutLink === 1) {
    window.open(menu.link, "_blank");
  } else {
    router.push(menu.link);
  }

  dialog.value = false;
};

/**
 * 处理移动端菜单项点击事件
 * @param {Object} menu - 菜单项数据对象
 * @param {Number} index - 菜单索引
 */
const handleMobileMenuClick = (menu: any, index: number) => {
  if (menu.clickable === 0) {
    return;
  }

  currentIdx.value = index;

  if (menu.isOutLink === 1) {
    window.open(menu.link, "_blank");
  } else {
    router.push(menu.link);
  }

  dialog.value = false;
};

/**
 * 处理移动端子菜单项点击事件
 * @param {Object} child - 子菜单项数据对象
 * @param {Number} parentIndex - 父菜单索引
 */
const handleMobileSubMenuClick = (child: any, parentIndex: number) => {
  if (child.clickable === 0) {
    return;
  }

  currentIdx.value = parentIndex;

  if (child.isOutLink === 1) {
    window.open(child.link, "_blank");
  } else {
    router.push(child.link);
  }

  dialog.value = false;
};

/**
 * 处理普通菜单点击（如搜索）
 * @param {String} link - 跳转链接
 */
const handleMenuClick = (link: string) => {
  router.push(link);
  dialog.value = false;
};
/**
 * 处理PC端菜单项点击事件
 * @param {Object} menu - 菜单项数据对象
 * @param {Number} index - 菜单索引
 */
const handlePcMenuClick = (menu: any, index: number) => {
  if (menu.clickable === 0) {
    return;
  }

  currentIdx.value = index;

  if (menu.isOutLink === 1) {
    window.open(menu.link, "_blank");
  } else {
    router.push(menu.link);
  }
};

/**
 * 处理PC端子菜单项点击事件
 * @param {Object} child - 子菜单项数据对象
 * @param {Number} parentIndex - 父菜单索引
 */
const handlePcSubMenuClick = (child: any, parentIndex?: number) => {
  if (child.clickable === 0) {
    return;
  }

  // 如果提供了父菜单索引，设置高亮状态
  if (parentIndex !== undefined) {
    currentIdx.value = parentIndex;
  }

  if (child.isOutLink === 1) {
    window.open(child.link, "_blank");
  } else {
    router.push(child.link);
  }
};

// 搜索相关
const searchKeyword = ref("");

// 延时器引用
let hoverTimer: NodeJS.Timeout | null = null;

/**
 * 菜单悬停处理
 * @param {Object} menu - 菜单项数据对象
 * @param {Number} index - 菜单索引
 */
const handleMenuHover = (menu: any, index: number) => {
  // 清除之前的延时器
  if (hoverTimer) {
    clearTimeout(hoverTimer);
    hoverTimer = null;
  }
  hoveredMenu.value = menu;
};

/**
 * 菜单离开处理
 */
const handleMenuLeave = () => {
  // 设置延时隐藏，给用户时间移动到下拉菜单
  hoverTimer = setTimeout(() => {
    hoveredMenu.value = null;
  }, 150);
};

/**
 * 保持下拉菜单打开
 */
const keepDropdownOpen = () => {
  // 当鼠标进入下拉菜单时，清除隐藏延时器
  if (hoverTimer) {
    clearTimeout(hoverTimer);
    hoverTimer = null;
  }
};

/**
 * 下拉菜单离开处理
 */
const handleDropdownLeave = () => {
  // 立即隐藏下拉菜单
  hoveredMenu.value = null;
};

/**
 * 处理搜索
 */
const handleSearch = () => {
  if (searchKeyword.value.trim()) {
    navigateTo(`/search?keyword=${encodeURIComponent(searchKeyword.value)}`);
  }
};

// 处理搜索框回车事件
const handleSearchKeyup = (event: KeyboardEvent) => {
  if (event.key === "Enter") {
    handleSearch();
  }
};
</script>

<style lang="scss" scoped>
// 通用样式类
.px-100 {
  padding-left: 100px;
  padding-right: 100px;

  @media screen and (max-width: 1200px) {
    padding-left: 50px;
    padding-right: 50px;
  }

  @media screen and (max-width: 768px) {
    padding-left: 20px;
    padding-right: 20px;
  }
}

// Tailwind CSS 替换类
.d-flex {
  display: flex;
}

.d-block {
  display: block;
}

.d-none {
  display: none;
}

.d-sm-block {
  @media screen and (min-width: 576px) {
    display: block;
  }
}

.d-sm-none {
  @media screen and (min-width: 576px) {
    display: none;
  }
}

.d-md-block {
  @media screen and (min-width: 768px) {
    display: block;
  }
}

.d-lg-block {
  @media screen and (min-width: 992px) {
    display: block;
  }
}

.d-xl-block {
  @media screen and (min-width: 1200px) {
    display: block;
  }
}

.d-lg-none {
  @media screen and (min-width: 992px) {
    display: none;
  }
}

.d-md-none {
  @media screen and (min-width: 768px) {
    display: none;
  }
}

.justify-around {
  justify-content: space-around;
}

.align-center {
  align-items: center;
}

.text-center {
  text-align: center;
}

.text-md-left {
  @media screen and (min-width: 768px) {
    text-align: left;
  }
}

.text-lg-left {
  @media screen and (min-width: 992px) {
    text-align: left;
  }
}

.text-xl-left {
  @media screen and (min-width: 1200px) {
    text-align: left;
  }
}

.w-100 {
  width: 100%;
}

.h-100 {
  height: 100%;
}

.mx-auto {
  margin-left: auto;
  margin-right: auto;
}

.px-3 {
  padding-left: 1rem;
  padding-right: 1rem;
}

.px-xl-0 {
  @media screen and (min-width: 1200px) {
    padding-left: 0;
    padding-right: 0;
  }
}

.py-2 {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.pt-5 {
  padding-top: 3rem;
}

.mt-3 {
  margin-top: 1rem;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-sm-2 {
  @media screen and (min-width: 576px) {
    margin-top: 0.5rem;
  }
}

.mt-md-0 {
  @media screen and (min-width: 768px) {
    margin-top: 0;
  }
}

.mt-lg-0 {
  @media screen and (min-width: 992px) {
    margin-top: 0;
  }
}

.mt-xl-0 {
  @media screen and (min-width: 1200px) {
    margin-top: 0;
  }
}

.mb-2 {
  margin-bottom: 0.5rem;
}

.ml-1 {
  margin-left: 0.25rem;
}

.ml-2 {
  margin-left: 0.5rem;
}

.ml-4 {
  margin-left: 1.5rem;
}

.mr-1 {
  margin-right: 0.25rem;
}

.mr-2 {
  margin-right: 0.5rem;
}

.flex-column {
  flex-direction: column;
}

.font-weight-bold {
  font-weight: bold;
}

.on_hover {
  cursor: pointer;
  transition: all 0.3s ease;

  &:hover {
    opacity: 0.8;
    transform: translateY(-2px);
  }
}

.img_fit {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-responsive {
  max-width: 100%;
  height: auto;
}

// 交互类
.on_hover {
  cursor: pointer;
  transition: all 0.3s ease;
  &:hover {
    opacity: 0.8;
    transform: translateY(-2px);
  }
}

// 自定义间距类
.px-100 {
  padding-left: 100px;
  padding-right: 100px;
  @media screen and (max-width: 1200px) {
    padding-left: 50px;
    padding-right: 50px;
  }
  @media screen and (max-width: 768px) {
    padding-left: 20px;
    padding-right: 20px;
  }
}

/* ==========================================================================
   页面布局组件
   ========================================================================== */

// 头部导航
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  transition: all 0.3s ease-in-out;
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
  height: 90px;
  @media screen and (max-width: 768px) {
    height: 64px;
  }
}

// Logo 区域
.logo-section {
  flex: 0 0 auto;
}

.logo-link {
  display: block;
  text-decoration: none;
}

.logo-img {
  height: 48px;
  width: auto;
  object-fit: contain;

  @media screen and (max-width: 768px) {
    height: 36px;
  }

  @media screen and (max-width: 480px) {
    height: 32px;
  }
}

.logo {
  img {
    width: 150px;
    @media screen and (max-width: 600px) {
      width: 134px;
    }
  }
}

.title {
  img {
    width: 100px;
    margin-left: 14px;
  }
  &:hover {
    cursor: pointer;
  }
}

// 导航菜单区域
.nav-section {
  flex: 1;
  justify-content: flex-end;
  padding-right: 40px;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-item {
  position: relative;
  height: 90px;
  display: flex;
  align-items: center;
  transition: all 0.3s ease;

  &:hover {
    .nav-link:not(.disabled-link) {
      color: $custom-primary;
    }
    .dropdown-icon {
      transform: rotate(180deg);
    }
  }

  &.active {
    .nav-link {
      color: $custom-primary;
      font-weight: 600;
    }
  }
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  text-decoration: none;
  color: #333;
  font-weight: 500;
  font-size: 14px;
  transition: color 0.3s ease;
  white-space: nowrap;
}

.disabled-link {
  color: #999;
  cursor: not-allowed;
}

.dropdown-icon {
  font-size: 12px;
  transition: transform 0.3s ease;
}

// 搜索区域
.search-section {
  flex: 0 0 auto;
}

.search-container {
  position: relative;
  width: 280px;
}

.search-input {
  width: 100%;
  padding: 8px 45px 8px 12px;
  border: 2px solid #e0e0e0;
  border-radius: 25px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.3s ease;

  &:focus {
    border-color: $custom-primary;
  }
}

.search-btn {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  transition: color 0.3s ease;
  padding: 5px;

  &:hover {
    color: #007bff;
  }
}

// 移动端菜单按钮
.mobile-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
  color: #333;
  font-size: 20px;
  padding: 8px;

  @media screen and (min-width: 1024px) {
    display: none;
  }
}

// 移动端菜单容器
.mobile-menu-container {
  background: white;
  height: 100vh;
  overflow-y: auto;
  padding: 0;
}

.mobile-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: rgba($custom-primary, 0.05);
}

.mobile-menu-body {
  padding: 16px 0;
}

.mobile-menu-item {
  border-bottom: 1px solid #f3f4f6;
}

.mobile-menu-link {
  display: block;
  padding: 16px 20px;
  color: #374151;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;

  &:hover {
    background: rgba($custom-primary, 0.1);
    color: $custom-primary;
  }

  &.disabled {
    color: #9ca3af;
    cursor: not-allowed;
  }
}

.mobile-menu-group {
  .mobile-menu-title {
    padding: 16px 20px 8px;
    font-weight: 600;
    color: #111827;
    font-size: 16px;
  }
}

.mobile-submenu {
  background: #f9fafb;

  .mobile-submenu-link {
    display: block;
    padding: 12px 20px 12px 40px;
    color: #6b7280;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s ease;

    &:hover {
      background: rgba($custom-primary, 0.1);
      color: $custom-primary;
    }

    &.disabled {
      color: #d1d5db;
      cursor: not-allowed;
    }
  }
}

/* ==========================================================================
   下拉菜单组件
   ========================================================================== */

.mega-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100vw;
  height: 300px;
  background: white;
  box-shadow: 0 0px 0 rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-20px);
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  z-index: 1000;
  overflow: hidden;

  &.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    animation: slideDown 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  }
}

@keyframes slideDown {
  0% {
    opacity: 0;
    transform: translateY(-20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.mega-dropdown-content {
  display: flex;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 40px 20px;
}

.dropdown-left {
  flex: 0 0 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 40px;
}

.dropdown-image {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 8px;
}

.dropdown-center {
  flex: 1;
  padding: 0 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.dropdown-title {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin-bottom: 16px;
}

.dropdown-description {
  font-size: 16px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 20px;
}

.learn-more-btn {
  background: $custom-primary;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.3s ease;
  text-decoration: none;
  display: inline-block;
  width: 120px;
  text-align: center;
}

.dropdown-right {
  flex: 0 0 400px;
  padding-left: 40px;
  min-width: 400px;
}

.children-list {
  height: 100%;
}

.children-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #f0f0f0;
}

.children-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.child-item {
  padding: 12px 16px;
  border-radius: 6px;
  transition: all 0.2s ease;
  cursor: pointer;

  &:hover {
    background-color: #f8f9fa;
    transform: translateX(4px);

    .child-link:not(.disabled) {
      color: $custom-primary;
    }
  }

  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;

    &:hover {
      background-color: transparent;
      transform: none;
    }
  }
}

.child-link {
  display: block;
  color: #333;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.2s ease;

  &.disabled {
    color: #999;
  }
}

/* ==========================================================================
   移动端菜单组件
   ========================================================================== */

.mobile-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;

  &.active {
    opacity: 1;
    visibility: visible;
  }
}

.mobile-menu {
  position: fixed;
  top: 0;
  right: -300px;
  width: 300px;
  height: 100%;
  background-color: #ffffff;
  z-index: 999;
  transition: right 0.3s ease;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);

  &.active {
    right: 0;
  }
}

.mobile-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid #f0f0f0;
  background-color: $custom-primary;
  color: white;

  .menu-title {
    font-size: 16px;
    font-weight: bold;
  }

  .close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
  }
  @media screen and (max-width: 768px) {
    .menu-title {
      font-size: 14px;
    }
  }
}

.mobile-menu-content {
  padding: 0;
  height: calc(100% - 80px);
  overflow-y: auto;
}

.search-item {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  color: #0251ad;
  font-weight: 500;

  &:hover {
    background-color: #f8f9fa;
  }
}

.menu-item {
  border-bottom: 1px solid #f0f0f0;

  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  &.active {
    .menu-item-content {
      background-color: rgba($custom-primary, 0.1);
      color: $custom-primary;
      font-weight: 600;

      .sectionIcon {
        color: $custom-primary;
      }
    }
  }
  @media screen and (max-width: 768px) {
    font-size: 14px;
  }
}

.menu-item-content {
  padding: 15px 20px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  font-weight: 500;
  color: #333;

  &:hover {
    background-color: #f8f9fa;
  }
}

.submenu {
  background-color: #f8f9fa;
  border-top: 1px solid #e9ecef;
}

.submenu-item {
  padding: 12px 40px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  color: #666;
  border-bottom: 1px solid #e9ecef;

  &:hover {
    background-color: #e9ecef;
  }

  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  &:last-child {
    border-bottom: none;
  }
}

.menu-divider {
  height: 1px;
  background-color: #f0f0f0;
}

.mobile-menu-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 10px;
  color: #0251ad;
}

/* ==========================================================================
   主内容区域
   ========================================================================== */

.app_main {
  position: relative;
  background-color: #f8f8f8;
  min-height: 600px;
  margin: 0 auto;
  margin-top: 90px;

  @media screen and (max-width: 600px) {
    margin-top: 64px;
  }
}

// 快捷图标
.quick_icons {
  position: fixed;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  top: 65%;
  right: 0;
  transform: translate(-10%, -50%);
  z-index: 999;

  @media screen and (max-width: 600px) {
    display: none;
  }
}

.quick_icons_mobile {
  position: fixed;
  display: none;
  z-index: 999;
  bottom: 0;
  right: 12px;
  width: 120px;
  height: 36px;
  background-color: #2e3192;
  text-align: center;
  line-height: 40px;
  color: white;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;

  @media screen and (max-width: 600px) {
    display: block;
  }
}

/* ==========================================================================
   页脚组件
   ========================================================================== */

.footer_wrapper {
  box-sizing: border-box;
  background-color: $custom-secondary;
  padding: 20px 0 4px;
  opacity: 0.9;

  @media screen and (max-width: 600px) {
    padding: 26px 0 45px;
  }
}

.footer_content_wrap {
  width: 1240px;
  max-width: $custom-maxwidth;

  @media screen and (max-width: 1650px) {
    width: 96%;
  }

  @media screen and (min-width: 1650px) {
    width: 90%;
  }
}

.footer_content_item {
  width: 336px;
  margin: 0 auto;
  color: #c1d8ea;
  font-size: 14px;

  .official_accounts {
    width: 100px;
    height: 100px;

    @media screen and (max-width: 600px) {
      margin: 0 auto;
    }
  }

  .subscribe {
    img {
      width: 28px;
    }
  }
}

.item_title {
  font-size: 14px;
  font-weight: bold;
  color: #ffffff;

  @media screen and (max-width: 600px) {
    margin: 0 auto;
  }
}

.item_sub_title {
  font-weight: 500;
  margin-bottom: 4px;
}

.nav_link {
  font-size: 14px;
  color: #c1d8ea;
  text-decoration: none;
  transition: color 0.3s ease;

  &:hover {
    color: #c1272d;
  }
}

.link_item {
  margin-bottom: 18px;
}

.quick_link,
.frendily_link {
  @media screen and (max-width: 600px) {
    display: none !important;
  }
}

// 页脚菜单区域
.menu_sections {
  .footer_section {
    color: #c1d8ea;
    font-size: 14px;
  }

  .children_list {
    .child_item {
      &.has_divider {
        border-bottom: 1px solid rgba($custom-white, 0.15);
      }
    }
  }

  .sectionIcon,
  .childIcon {
    color: $custom-primary;
  }
}

// 公司信息区域
.company_info_section {
  .sectionIcon {
    color: $custom-primary;
  }
}

.sub_item {
  .wxcode {
    width: 80px;
    text-align: center;
    font-size: 12px;
    color: #ffffff;
  }
}

// 备案信息
.record_information {
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 1400px;
  margin: auto;
  font-size: 14px;
  color: #c1d8ea;

  .record {
    display: flex;
    justify-content: center;
    text-align: center;
    flex-wrap: wrap;
    align-items: center;
  }

  @media screen and (max-width: 1650px) {
    width: 90%;
  }

  @media screen and (max-width: 450px) {
    flex-direction: column;
  }
}

.copy_right {
  font-size: 14px;
  color: #c1d8ea;
}

/* ==========================================================================
   PC端菜单禁用状态
   ========================================================================== */

.head_item {
  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;

    .nav-link {
      pointer-events: none;
      color: #999;
    }
  }
}

.list_item {
  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;

    a,
    span {
      pointer-events: none;
      color: #999;
    }
  }
}

/* ==========================================================================
   响应式设计
   ========================================================================== */

@media (max-width: 1200px) {
  .mega-dropdown-content {
    padding: 30px 15px;
  }

  .dropdown-left {
    flex: 0 0 250px;
    padding-right: 30px;
  }

  .dropdown-center {
    padding: 0 30px;
  }

  .dropdown-right {
    flex: 0 0 300px;
    padding-left: 30px;
  }
}

@media (max-width: 992px) {
  .mega-dropdown {
    display: none;
  }
}
</style>
